/*
 * File:   Layer.h
 * Author: ranjeet
 *
 * Created on January 1, 2009, 11:37 AM
 */

#include "SpriteList.h"
#include "SpriteInstanceList.h"
#include "Thread_Wrapper.h"
#include "Viewport.h"
#include "Debug.h"


#ifndef _LAYER_H
#define	_LAYER_H

#define INVALID_LAYER_ID    -1

class Layer : public Thread_Wrapper {
    int m_layerId;
    Viewport &viewport;
    SpriteInstanceList spriteInstanceList;
    SpriteList &spritelist;
    bool m_bVisible;
    char *name;
    int zlevel; //increases from inside to outside
    int scroll_factor;  //used to decide the speed of scrolling
    SDL_Surface *surface;

    bool layer_shared;  //layer is shared or dedicated
    bool rendering_threaded;    //rendering is to be done inside a new thread or ...

    void render();
public:
    void execute();
    SDL_Surface *get_surface();
    Layer(uint layerId, int _scroll_factor);
    bool add(uint imgId, uint spriteId, SDL_Rect rect, bool visible = true, bool solid = true);
    bool makeSpriteAtXYActive(int x, int y);
    void moveActiveSpritebyXY(Sint16 x, Sint16 y);
    bool activeSpriteBringToFront();
    bool activeSpriteSendToBack();
    bool activeSpriteToggleSolid();
    bool activeSpriteToggleVisible();
    bool activeSpriteDelete();
    uint getLayerId();
    void setLayerId(uint layerId);
    void setVisible(bool visible);
    bool isVisible();

    list<SpriteInstance>::iterator getspriteInstanceListIteratorBegin();
    list<SpriteInstance>::iterator getspriteInstanceListIteratorEnd();

    ~Layer();
    void clear();
};

inline void Layer::clear() {
    spriteInstanceList.clear();
    SDL_FreeSurface(surface);
    surface = NULL;
};

inline SDL_Surface *Layer::get_surface() {
    return surface;
};

inline uint Layer::getLayerId()
{
    return m_layerId;
};

inline void Layer::setLayerId(uint layerId)
{
    m_layerId = layerId;
};

inline void Layer::setVisible(bool visible)
{
    m_bVisible = visible;
}

inline bool Layer::isVisible()
{
    return m_bVisible;
}

inline list<SpriteInstance>::iterator Layer::getspriteInstanceListIteratorBegin()
{

    return spriteInstanceList.getSpriteInstances().begin();
}

inline list<SpriteInstance>::iterator Layer::getspriteInstanceListIteratorEnd()
{
   return spriteInstanceList.getSpriteInstances().end();
}

#endif	/* _LAYER_H */

